//
//  OADExtendableTableViewController.m
//  OASDK_Works
//
//  Created by ChenJie on 5/23/20.
//  Copyright © 2020 Mist. All rights reserved.
//

#import "OADExtendableTableViewController.h"
#import "OASDK.h"
#import "OADExpendableCell.h"
#import "OADMocker.h"

@interface OADExtendableTableViewController ()

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation OADExtendableTableViewController

#pragma mark - ViewController lifecycle

- (instancetype)init {
    self = [super init];
    if (self) {
        [self buildDataSource];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = NSStringFromClass(self.class);
    
    [self.view addSubview:self.tableView];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}

- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    
    CGFloat topMark = 0;
    CGSize viewSize = self.view.bounds.size;
    
    self.tableView.frame = CGRectMake(0, topMark, viewSize.width, viewSize.height - topMark);
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

#pragma mark - Public methods



#pragma mark - Private methods

- (void)buildDataSource {
    OATableConfig *tableConfig = self.tableView.oa_tableConfig;
    
    for (NSInteger i = 0; i < 20; i++) {
        OACellConfig *cell =
        [tableConfig addCellWithType:@"OADExpendableCell" viewModel:@{
            @"title": [NSString stringWithFormat:@"Title at index %ld", (long)i],
            @"content": [OADMocker mockContent],
        }];
        
        cell.cellDidSelect = ^(OACellConfig *cellConfig) {
            OADExpendableCellViewModel *cellViewModel = cellConfig.cellViewModel;
            cellViewModel.isExpanded = !cellViewModel.isExpanded;
            [cellConfig updateCellWithAnimation:UITableViewRowAnimationFade];
        };
    }
}

#pragma mark - Event response methods



#pragma mark - Deletate methods



#pragma mark - Setter



#pragma mark - Getter

OAGetTableView(tableView, ^(UITableView *tableView){
    tableView.backgroundColor = OAColorString(@"efefef");
})

#pragma mark - Memory management

- (void)dealloc {
}

@end
